package compiles

import (
	"fmt"

	"Hy.OJudge.Server/untity"
	"github.com/google/uuid"
)

//代码执行器。。
type impleCodes struct{}

func NewImple() impleCodes {
	return impleCodes{}
}

var (
	GccPaths   string           = "/usr/bin/gcc"
	Bash       string           = "/usr/bin/bash"
	ProcessObj untity.ProUntity = untity.ProUntity{}
)

//用来执行c语言代码
func (im *impleCodes) GccImple(Code string) string {
	Name := uuid.New().String() //随机生成 最大程序支持并发访问

	if err := ProcessObj.CreateCodeFiles(Code, Name+".c"); err != nil {
		panic(err)
	}
	//currPaths := ProcessObj.GetCurrentPath()
	//ImpFile := Name + ".out"
	Name = "a"
	Args := make([]string, 1)
	Args[0] = "gcc " + "./File/" + Name + ".c"
	fmt.Println(Args[0])
	//编译结果
	CompileRes := ProcessObj.StartProcess(GccPaths, Args)

	fmt.Println(CompileRes)
	// Args = make([]string, 1)
	// Args[0] = "./" + ImpFile
	// //最终结果
	// r := ProcessObj.StartProcess(Bash, Args)
	// fmt.Println(r)

	return ""
}
